package edu.wust;

import static java.lang.String.valueOf;

public class exam36 {

    public static boolean qaq(int num){
        String s1=valueOf(num),s2="";
        int temp=num;
        while(temp!=0){
            s2+=String.valueOf(temp%2);
            temp=temp/2;
        }
        StringBuilder s11=new StringBuilder(s1);
        StringBuilder s22=new StringBuilder(s2);
        if(s1.equals(s11.reverse().toString())&&s2.equals(s22.reverse().toString()))
            return true;
        return false;
    }
    public static void main(String[] args) {
        int sum=0;
        for(int i=1;i<1000000;++i){
            if(qaq(i)){
                sum+=i;
            }
        }
        System.out.println(sum);
    }
}

